package de.dhbw.tinf11b.vfb.tests;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.junit.Test;

import de.dhbw.tinf11b.vfb.Course;
import de.dhbw.tinf11b.vfb.CourseManager;
import de.dhbw.tinf11b.vfb.Curriculum;
import de.dhbw.tinf11b.vfb.CurriculumManager;
import de.dhbw.tinf11b.vfb.DegreeType;
import de.dhbw.tinf11b.vfb.Examination;
import de.dhbw.tinf11b.vfb.Module;
import de.dhbw.tinf11b.vfb.Unit;
import de.dhbw.tinf11b.vfb.exceptions.CourseNotFoundException;
import de.dhbw.tinf11b.vfb.exceptions.CurriculumNotFoundException;
import de.dhbw.tinf11b.vfb.exceptions.WeightingsMismatchException;

public class CourseManagerTest {

	@Test
	public void testGetCourses() throws WeightingsMismatchException, CurriculumNotFoundException {
		CourseManager courseManager = CourseManager.getInstance();
		
		CurriculumManager curriculumManager = new CurriculumManager();
		
		Examination e1;
		HashMap<Examination, Integer> e;
		Unit u1, u2;
		Module m;
		List<Module> moduleList = new LinkedList<Module>();
		HashMap<Unit, Float> units;
		
		
		// MATHEMATIK I
		e1 = new Examination(true, 90);
		e = new HashMap<Examination, Integer>();
		e.put(e1, 1);
		u1 = new Unit("Lineare Algebra", e);
		
		e1 = new Examination(true, 90);
		e = new HashMap<Examination, Integer>();
		e.put(e1, 1);
		u2 = new Unit ("Analysis", e);
		
		units = new HashMap<Unit, Float>();
		units.put(u1, (float) 0.5);
		units.put(u2, (float) 0.5);
		m = new Module("Mathematik I", units, 1, 8, 96, 144);
		moduleList.add(m);
		
		curriculumManager.addCurriculum("Angewandte Informatik Stand 2011", DegreeType.BACHELOR_OF_SCIENCE, moduleList);
		
		Curriculum curriculum = curriculumManager.getCurriculum("Angewandte Informatik Stand 2011");
			
		courseManager.addCourse("TINF11B", 2011, "1.11", curriculum, "Schwinn");
		
		assertFalse(courseManager.getCourses().isEmpty());
	}

	@Test
	public void testGetCourseByName() throws WeightingsMismatchException, CurriculumNotFoundException, CourseNotFoundException {
		CourseManager courseManager = CourseManager.getInstance();
		
		CurriculumManager curriculumManager = new CurriculumManager();
		
		Examination e1;
		HashMap<Examination, Integer> e;
		Unit u1, u2;
		Module m;
		List<Module> moduleList = new LinkedList<Module>();
		HashMap<Unit, Float> units;
		
		
		// MATHEMATIK I
		e1 = new Examination(true, 90);
		e = new HashMap<Examination, Integer>();
		e.put(e1, 1);
		u1 = new Unit("Lineare Algebra", e);
		
		e1 = new Examination(true, 90);
		e = new HashMap<Examination, Integer>();
		e.put(e1, 1);
		u2 = new Unit ("Analysis", e);
		
		units = new HashMap<Unit, Float>();
		units.put(u1, (float) 0.5);
		units.put(u2, (float) 0.5);
		m = new Module("Mathematik I", units, 1, 8, 96, 144);
		moduleList.add(m);
		
		curriculumManager.addCurriculum("Angewandte Informatik Stand 2011", DegreeType.BACHELOR_OF_SCIENCE, moduleList);
		
		Curriculum curriculum = curriculumManager.getCurriculum("Angewandte Informatik Stand 2011");
			
		courseManager.addCourse("TINF11B", 2011, "1.11", curriculum, "Schwinn");
		
		Course course = courseManager.getCourseByName("TINF11B");
		
		assertTrue(course.getName().equals("TINF11B"));
	}

	@Test
	public void testAddCourse() throws WeightingsMismatchException, CurriculumNotFoundException {
		CourseManager courseManager = CourseManager.getInstance();
		
		CurriculumManager curriculumManager = new CurriculumManager();
		
		Examination e1;
		HashMap<Examination, Integer> e;
		Unit u1, u2;
		Module m;
		List<Module> moduleList = new LinkedList<Module>();
		HashMap<Unit, Float> units;
		
		
		// MATHEMATIK I
		e1 = new Examination(true, 90);
		e = new HashMap<Examination, Integer>();
		e.put(e1, 1);
		u1 = new Unit("Lineare Algebra", e);
		
		e1 = new Examination(true, 90);
		e = new HashMap<Examination, Integer>();
		e.put(e1, 1);
		u2 = new Unit ("Analysis", e);
		
		units = new HashMap<Unit, Float>();
		units.put(u1, (float) 0.5);
		units.put(u2, (float) 0.5);
		m = new Module("Mathematik I", units, 1, 8, 96, 144);
		moduleList.add(m);
		
		curriculumManager.addCurriculum("Angewandte Informatik Stand 2011", DegreeType.BACHELOR_OF_SCIENCE, moduleList);
		
		Curriculum curriculum = curriculumManager.getCurriculum("Angewandte Informatik Stand 2011");
			
		courseManager.addCourse("TINF11B", 2011, "1.11", curriculum, "Schwinn");
		
		assertFalse(courseManager.getCourses().isEmpty());
	}

}
